#include <iostream>
#include <string>
#include <map>

using namespace std;
// 67% 
int main(){

	string s1,s2;
	cin >> s1 >> s2;
	map<char,int> m;
	for(int i = 0; i < s1.size(); ++i){
		char c1 = s1[i]; 
		char c2 = s2[i];
		m[c1]++;
		m[c2]--;
	}
	
	map<char,int> m1;
	map<char,int> m2;
	
	int ans = 0;
	
	for(auto val : m){
		if(val.second > 0){
			ans += val.second;
			m1[val.first] = val.second;
		}
		if(val.second < 0){
			m2[val.first] = -val.second;
		}
	}
	
	for(int i = 0; i < s1.size(); ++i){
		char c1 = s1[i];
		if(m1.empty()) break;
		if(m1.count(c1)){
			auto it = m2.begin();
			if(it->first < c1){
				s1[i] = it->first;
				--(it->second);
				--m1[c1];
				if(!m1[c1]) m1.erase(c1);
				if(!it->second) m2.erase(it);
			}/*else{
				break;
			}*/
		}
	}

	
	for(int i = s1.size() - 1; i >= 0; --i){
		char c1 = s1[i];
		if(m1.empty()) break;
		if(m1.count(c1)){
			auto it = m2.end();
			--it;
			s1[i] = it->first;
			--(it->second);
			--m1[c1];
			if(!m1[c1]) m1.erase(c1);
			if(!it->second) m2.erase(it);
		}
	}
	
	cout << ans << endl << s1;
	
	return 0;
}

